/*
  S.M.A.C.K - An operating system kernel
  Copyright (C) 2010,2011 Mattias Holm and Kristian Rietveld
  For licensing and a full list of authors of the kernel, see the files
  COPYING and AUTHORS.
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <syscalls.h>

static void
list_directory(const char *name)
{
  int handle;
  struct dir_entry *entry;

  handle = opendir(name);
  if (handle < 0)
    {
      printf("ls: could not open directory '%s'\r\n", name);
      return;
    }

  while ((entry = readdir(handle)) != NULL)
    {
      switch (entry->type)
        {
          case TYPE_DEVICE:
            printf("c\t%s\n", entry->name);
            break;

          case TYPE_MOUNT:
            printf("m\t%s\n", entry->name);
            break;

          case TYPE_DATA:
            printf("-\t%s\t%d\n", entry->name, entry->size);
            break;

          case TYPE_DIR:
            printf("d\t%s\n", entry->name);
            break;
        }
    }
  closedir(handle);
}

int
main(int argc, char **argv)
{
  char buf[256];

  getwd(buf, 256);
  list_directory(buf);
}
